package by.amakarevich.webapp.page;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import by.amakarevich.datamodel.Product;
import by.amakarevich.webapp.app.BasicAuthenticationSession;
import by.amakarevich.webapp.app.SecuredLinkForAdmin;
import by.amakarevich.webapp.page.booking.BookingPage;
import by.amakarevich.webapp.page.booking.user.UserBookingPage;
import by.amakarevich.webapp.page.edit.ProductCreateEditPage;
import by.amakarevich.webapp.page.home.HomePage;
import by.amakarevich.webapp.page.kit.KitPage;
import by.amakarevich.webapp.page.kit.dimensions.DimensionsKitPage;
import by.amakarevich.webapp.page.kit.gamma.GammaKitPage;
import by.amakarevich.webapp.page.kit.panna.PannaKitPage;
import by.amakarevich.webapp.page.kit.riolis.RiolisKitPage;
import by.amakarevich.webapp.page.kit.rto.RtoKitPage;
import by.amakarevich.webapp.page.kit.zolotoeruno.ZolotoeRunoKitPage;
import by.amakarevich.webapp.page.lang.LanguageSelectionPanel;
import by.amakarevich.webapp.page.login.LoginPage;
import by.amakarevich.webapp.page.login.component.LoginLogoutPanel;
import by.amakarevich.webapp.page.shoppingcart.ShoppingCartPage;
import by.amakarevich.webapp.page.tambour.TambourPage;
import by.amakarevich.webapp.page.thread.ThreadPage;
import by.amakarevich.webapp.page.thread.dmc.DMCThreadPage;
import by.amakarevich.webapp.page.thread.gamma.GammaThreadPage;

public abstract class BaseLayout extends WebPage {

	@Override
	protected void onInitialize() {
		super.onInitialize();
		add(new Label("headerTitle", getPageTitle()));
		add(new FeedbackPanel("feedbackpanel"));
		add(new LanguageSelectionPanel("lang-select"));
		add(new LoginLogoutPanel("login-logout-panel"));
		
		add(new Link("home-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new HomePage());
			}
		});
		add(new Link("kit-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new KitPage());
			}
		});
		add(new Link("gamma-kit-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new GammaKitPage());
			}
		});
		add(new Link("panna-kit-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new PannaKitPage());
			}
		});
		add(new Link("dimensions-kit-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new DimensionsKitPage());
			}
		});
		add(new Link("rto-kit-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new RtoKitPage());
			}
		});
		add(new Link("zolotoe-runo-kit-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new ZolotoeRunoKitPage());
			}
		});
		add(new Link("riolis-kit-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new RiolisKitPage());
			}
		});
		add(new Link("tambour-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new TambourPage());
			}
		});
		add(new Link("thread-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new ThreadPage());
			}
		});
		add(new Link("gamma-thread-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new GammaThreadPage());
			}
		});
		add(new Link("dmc-thread-page-link") {
			@Override
			public void onClick() {
				setResponsePage(new DMCThreadPage());
			}
		});
		
		add(new Link("shopping-cart-page-link") {
			@Override
			public void onClick() {
				if(BasicAuthenticationSession.get().getUser()!=null){
					setResponsePage(new ShoppingCartPage());
				}else{
					setResponsePage(new LoginPage());
				}
				
			}
		});
		
		Link<Void> securedCreateLink = new SecuredLinkForAdmin("product-create-page-link") {

			@Override
			public void onClick() {
				setResponsePage(new ProductCreateEditPage(new Product()));

			}
		};
		
		add(securedCreateLink);
		
		Link<Void> securedBookingLink = new SecuredLinkForAdmin("booking-page-link") {

			@Override
			public void onClick() {
				setResponsePage(new BookingPage());

			}
		};
		add(securedBookingLink);
		
		add(new Link("user-booking-page-link") {
			@Override
			public void onClick() {
				if(BasicAuthenticationSession.get().getUser()!=null){
					setResponsePage(new UserBookingPage(false, false));
				}else{
					setResponsePage(new LoginPage());
				}
			}
		});
		
	}
	
	protected IModel<String> getPageTitle() {
		return new Model<String>(getClass().getSimpleName());
	}
}